package com.symria.server.dao.common;

import java.util.Date;
import java.util.List;

import com.symria.framework.dao.util.TemplateDao;
import com.symria.framework.page.Page;
import com.symria.server.po.PackDateReport;
import com.symria.server.po.PackInfo;
import com.symria.server.po.UserInfo;
import com.symria.system.constants.ATTSystem;
import com.symria.system.statement.Statement;

public class ChannelDao extends TemplateDao {

	public UserInfo findUserByName(String userName) {
		Statement stms = stmsFactory.createStatement(" from UserInfo where userName=?");
		          stms.addParam(userName);
		return templateDao.find(stms,UserInfo.class);
	}
	public void searchPackReport(PackDateReport pdr,UserInfo user,Date beginDate,Date endDate,Page page){
		Statement stms = stmsFactory.createStatement(" from PackDateReport pdr where pdr.channelId=? and pdr.state=?");
		          stms.addParam(user.getUserId());
		          stms.addParam(ATTSystem.LOGIC_TRUE);
		          if(pdr!=null){
		        	  stms.append("and", "pdr.packId", "=", pdr.getPackId());
		        	  stms.appendBetween("and", "pdr.createDate", beginDate, endDate);
		          }
		          stms.addOrderBy(" pdr.createDate desc");
		          templateDao.search(stms, page); 
	}
	public List<PackInfo> queryPackInfo(Integer userId){
		  Statement stms = stmsFactory.createNativeStatement("SELECT {p.*} FROM PACK_INFO p WHERE p.ID IN (SELECT DISTINCT  pdr.PACK_ID FROM PACK_DATE_REPORT pdr WHERE pdr.CHANNEl_ID=? )");
	                stms.addParam(userId);
	                stms.addEntity("p", PackInfo.class);
	                //stms.addOrderBy("p.id desc");
	         return templateDao.query(stms);
	      
	}
}
